package game.module.hall.logic;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.module.club.dao.ClubRoomCache;

public class QipaiDataManager {

	private static Logger logger = LoggerFactory.getLogger(QipaiDataManager.class);

	static class SingletonHolder {
		static QipaiDataManager instance = new QipaiDataManager();
	}

	public static QipaiDataManager getInstance() {
		return SingletonHolder.instance;
	}

	private Map<String, Byte> roomTypeCache = new ConcurrentHashMap<>();

	public String generateRoomUuid() {
		String roomUuid = RandomStringUtils.randomNumeric(6);
		while (roomTypeCache.containsKey(roomUuid)) {
			roomUuid = RandomStringUtils.randomNumeric(6);
		}
		return roomUuid;
	}

	public void addRoomUuid(String roomUuid, byte roomType) {
		roomTypeCache.put(roomUuid, roomType);
	}

	public void removeRoomUuid(String roomUuid) {
		roomTypeCache.remove(roomUuid);
		ClubRoomCache.getInstance().removeClubRoom(roomUuid);
	}

	public Byte getRoomType(String roomUuid) {
		return roomTypeCache.get(roomUuid);
	}

	public static void main(String[] args) {
		Map<String, String> map = new HashMap<>();
		int n = 0;
		for (int i = 0; i < 100000; i++) {
			String num = RandomStringUtils.randomNumeric(6);
			if (map.containsKey(num)) {
				System.out.println("repeat cnt=" + n + " num =" + num);
				n++;
			}
			map.put(num, "1");
		}
	}

}
